import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

//存token
const state = {
    Authorization: localStorage.getItem('Authorization') ? localStorage.getItem('Authorization') : '',
}
//数据处理方法
const mutations = {
    setMenu: (state, data) => {
        state.menuList = data
    },
    setList: (state, data) => {
        state.routerList = data
    },
    changeLogin: (state, user) => {
        state.Authorization = user.Authorization;
        localStorage.setItem('Authorization', user.Authorization);
    }
};

const actions = {
    // 获取权限列表
    // getPermission({commit}) {
    //     return new Promise((resolve, reject) => {
    //         axios({
    //             url: '/api/user?id=' + localStorage.getItem('Authorization'),
    //             methods: 'get',
    //             data: {
    //             "token": localStorage.getItem('Authorization'),
    //             }
    //         }).then((res) => {
    //             // 存储权限列表
    //             commit('setList', res.data.data.routerLsit);
    //             commit('setMenu', res.data.data.menuList);
    //             resolve(res.data.data.routerLsit)
    //         }).catch(() => {
    //             reject()
    //         })
    //     })
    // }
}

const store = new Vuex.Store({
    state,
    mutations,
    actions
});

export default store;